<?php

namespace app\admin\model;

use think\Model;


class Lanmu extends Model
{

    

    

    // 表名
    protected $name = 'lanmu';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'lanmutype_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getLanmutypeList()
    {
        return [
            '0' => __('Lanmutype 0'),
            '1' => __('Lanmutype 1'),
            '2' => __('Lanmutype 2'),
            '3' => __('Lanmutype 3'),
//            '4' => '系列',
//            '5' => '材质',
        ];
    }

    public function getParentLanmu()
    {
        return $this->where('pid', 0)->select();
    }


    public function getLanmutypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['lanmutype']) ? $data['lanmutype'] : '');
        $list = $this->getLanmutypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
